package com.kaifamiao.www.demo.do0906;

import java.sql.*;

public class Demo02 {

    public static void main(String[] args) {
        String str = "2022-09-06";
        Date date = Date.valueOf(str);
        System.out.println(date);
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/kfm";
        String sql = "INSERT INTO EMP (empno,ename,hiredate) values(?,?,?)";
        try (
                Connection connection = DriverManager.getConnection(url,"root","");
                PreparedStatement preparedStatement = connection.prepareCall(sql);
                ){
                //设置参数
            preparedStatement.setInt(1,12);
            preparedStatement.setString(2,"abc");
            preparedStatement.setObject(3,date);
            //执行
            System.out.println(preparedStatement.executeUpdate());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
